#include "hal.h"
#include "mongoose_glue.h"

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>

#include "led_drv.h"

static int fd;

void my_get_led1(struct led1 *data)
{
    ioctl(fd, LED1_GET, &data->value);
}

void my_set_led1(struct led1 *data)
{
    ioctl(fd, LED1_SET, data->value);
}

void my_get_led2(struct led2 *data)
{
    ioctl(fd, LED2_GET, &data->value);
}

void my_set_led2(struct led2 *data)
{
    ioctl(fd, LED2_SET, data->value);
}

void led_init()
{
    fd = open("/dev/led_drv", O_RDWR);
    mongoose_set_http_handlers("led1", my_get_led1, my_set_led1);
    mongoose_set_http_handlers("led2", my_get_led2, my_set_led2);
}
